Processing of Binary (and Other Non-Parsed) Entities

Once you declare a binary entity, how it is processed is up to the XML processor.  Whether it appears as a hyperlink, expanded text showing the URI of the entity, or as a simple attribute assignment really depends on the application that you are using to view the document.  There are no requirements or standards on this feature as of yet.  

Tip:	If you are using an XML processor within a software 
	application, you can expand the URI and get the binary 
	content yourself.

Example of Using an External Binary Entity

The following example XML document references two binary entities, which are image files.  Each image is in a different format, namely GIF and JPG respectively.  

The contents of the XML document is:

<?xml version="1.0" standalone="no"?>
<!DOCTYPE body [

    <!NOTATION GIF SYSTEM "iexplore.exe">
    <!NOTATION JPG SYSTEM "iexplore.exe">

    <!ENTITY gif.xml SYSTEM "xml.gif" NDATA GIF>
    <!ENTITY jpg.xml SYSTEM "xml.jpg" NDATA JPG>

    <!ELEMENT body ANY>

    <!ELEMENT img EMPTY>
        <!ATTLIST img src ENTITY #REQUIRED>
]>
<body>
    <img src="gif.xml"/>
    <img src="jpg.xml"/>
</body>

File: Chapter 6\BinaryEntities.xml.

The first thing that you will notice is the two <!NOTATION> declarations.  One for each image type.  For our example, the helper application specified for both is Internet Explorer.  

<!NOTATION GIF SYSTEM "iexplore.exe">
<!NOTATION JPG SYSTEM "iexplore.exe">

The second thing to point out is the <!ENTITY> declarations for the specific files.  These point to a GIF file (entity) and a JPG file (entity) using a relative path and associate them with their respective types.

<!ENTITY gif.xml SYSTEM "xml.gif" NDATA GIF>
<!ENTITY jpg.xml SYSTEM "xml.jpg" NDATA JPG>

Third, let’s examine the attribute declaration that will reference these entities.  

<!ELEMENT img EMPTY>
    <!ATTLIST img src ENTITY #REQUIRED>

Finally, let’s look at the instances where we reference the entities in the content.

<img src="gif.xml"/>
<img src="jpg.xml"/>

The result is an XML document that is not standalone and references multiple binary entities.  Let’s look at the document in Internet Explorer.

File: Chapter 6\BinaryEntities.xml in IE5.

While we are on the topic of notations, the keyword NOTATION can be used in relation to enumerated attribute types.  Look at the following modification to the “src” attribute declaration.

<!ELEMENT img EMPTY>
    <!ATTLIST img src NOTATION (GIF | JPG) "GIF"> 

What the use of the NOTATION keyword does is limit the attribute value possibilities to a list of types previously declared as notations.  This is just another way to constrain an enumerated attribute type.

A Few Final Words on DTD’s and Modularity

XML inherited much from its SGML parent.  In fact, XML brings much of the power without a lot of the complexity.  One of the primary features that XML retained from SGML was the ability to define the content model using DTD’s.  It also retained the ability to physically break up that DTD and the document content while retaining the logical structure.  

As you design your content models, think of things that you can do to provide reusability among your documents and those created by other authors.  Here are some suggestions:

	Create a company wide standard set of character entities that 
	can be included in all of your documents.  This set could 
	include things like company logo references, positions and 
	titles, and other global definitions that have meaning in the 
	organization.

	Create a set of external DTD’s for defining common content 
	structures like company policies, project schedules, project 
	status reports, etc.

	Create multiple XML documents that include simple lists 
	(e.g. department names, contacts, etc.) that can be used by 
	multiple applications and departments.  Make those lists 
	available on a single physical source so that they can be used 
	by others throughout the company.

These are just a few ideas on how you can take advantage of the features that XML provides in regards to modularity.